﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FisheryPlatform.Common;
using FisheryPlatform.Common.StaticCache;
using FisheryPlatform.SiteConfig.FileStore;

namespace FisheryPlatform.SiteConfig
{
    /// <summary>
    /// 站点设置通用管理，只能放在通用层。
    /// </summary>
    public class SiteConfigManager
    {
        static SiteConfigManager()
        {
            var filePath = IOUtility.GetRootedFilePath(@"Config\ConfigFilePathSetting.config");
            FilePathSettings = (ConfigFilePathSetting)SerializerUtility.DeserializeFromXmlFile(filePath, typeof(ConfigFilePathSetting));
            _WebSiteInfo = new WebSiteInfo();
        }

        /// <summary>
        /// 配置文件路径
        /// </summary>
        public static ConfigFilePathSetting FilePathSettings
        {
            get;
            private set;
        }

        /// <summary>
        /// 数据库连接串
        /// </summary>
        public static DBInfoCollection DatabaseSettings
        {
            get
            {
                return FileCacheUtility.GetObjectFromXmlFile(FilePathSettings.DatabaseConfigPath, typeof(DBInfoCollection)) as DBInfoCollection;
            }
        }

        /// <summary>
        /// 程序设置
        /// </summary>
        public static AppSettingsCollection AppSettings
        {
            get
            {
                return FileCacheUtility.GetObjectFromXmlFile(FilePathSettings.AppSettingConfigPath, typeof(AppSettingsCollection)) as AppSettingsCollection;
            }
        }

        private static WebSiteInfo _WebSiteInfo = null;
        /// <summary>
        /// 站点
        /// </summary>
        public static WebSiteInfo WebSite
        {
            get
            {
                return _WebSiteInfo;
            }
        }

        public static FileServerMapCollection FileServerMapList
        {
            get
            {
                return FileCacheUtility.GetObjectFromXmlFile(FilePathSettings.FileServerMapPath, typeof(FileServerMapCollection)) as FileServerMapCollection;
            }
        }

        public static FileServerCollection FileServerList
        {
            get
            {
                return FileCacheUtility.GetObjectFromXmlFile(FilePathSettings.FileServerPath, typeof(FileServerCollection)) as FileServerCollection;
            }
        }
    }
}
